import Taro from '@tarojs/taro';
// const BASE_URL = 'http://192.168.130.48:8888'
// const BASE_URL = 'http://localhost:8080/api'
// const BASE_URL = 'http://ybjy.szzkba.cn:8888'
const BASE_URL = 'https://cxjadmin.szzkba.cn/api'
export function request(method = 'GET', url, data, token) {
    return new Promise(function (resolve, reject) {
        Taro.request({
            url: BASE_URL + url,
            data: data,
            method: method,
            // mode: 'no-cors',
            header: {
                'content-type': 'application/json',
                'X-Token': token || Taro.getStorageSync('token'),
                // 'Authorization': 'Bearer ' + Taro.getStorageSync('token')
            },
            success: function (res) {
                console.log("3333333333333")
                console.log(res)
                if (res.statusCode == 200 && res.data.resultCode == 200) {
                    resolve(res.data);
                } else if (res.statusCode == 200 && res.data.resultCode == 416) {
                    Taro.showModal({
                        title: '请登录',
                        content: '登录后体验更好的服务',
                        showCancel: false,
                        success: function (res) {
                            wx.reLaunch({
                                url: '/packageA/pages/mypage/index'
                            })
                        }
                    })
                    Taro.removeStorage({
                        key: 'token',
                        success: function (res) {
                            console.log(res)
                        }
                    })
                    Taro.removeStorage({
                        key: 'user',
                        success: function (res) {
                            console.log(res)
                        }
                    })
                    reject("登录已过期");
                } else {
                    resolve(res.data)
                }
            },
            fail: function (err) {
                console.log(err)
                reject("服务器连接异常，请检查网络");
            },
            complete: function () {
            }
        })
    })
}

